package com.cw.serviceimpl;

import com.cw.data.PageBean;
import com.cw.mapper.TbSellerMapper;
import com.cw.mapper.TbStatusMapper;
import com.cw.pojo.TbSeller;
import com.cw.pojo.TbStatus;
import com.cw.service.SellerService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@com.alibaba.dubbo.config.annotation.Service
public class SellerServiceImpl implements SellerService {

    @Autowired
    private TbSellerMapper tbSellerMapper;

    @Autowired
    private TbStatusMapper tbStatusMapper;

    @Override
    public Boolean checkName(String sellerId) {

        TbSeller ts = tbSellerMapper.checkName(sellerId);

        if (ts != null) {

            return false;
        }else {

            return true;
        }
    }

    @Override
    public void toRegister(TbSeller tbs) {

        tbSellerMapper.insertSelective(tbs);
    }

    @Override
    public TbSeller check(String username) {
        return tbSellerMapper.checkName(username);
    }

    @Override
    public List<TbStatus> getList() {
        return tbStatusMapper.selectByExample(null);
    }

    @Override
    public TbSeller getOneSellerInfo(String sellerId) {

        return tbSellerMapper.getOneSellerInfo(sellerId);
    }

    @Override
    public PageBean<TbSeller> getSellerInfo(Integer pageNumber, Integer pageSize, String name, String nickName, String status) {

        PageHelper.startPage(pageNumber, pageSize);

        List<TbSeller> tbSellerList = tbSellerMapper.getSellerInfo(name, nickName, status);

        PageInfo<TbSeller> pa = new PageInfo<>(tbSellerList);

        return new PageBean<>(pa.getPageNum(), pa.getPageSize(), pa.getPages(), pa.getTotal(), pa.getList());
    }

    @Override
    public void setStatus(String status, String sellerId) {

        tbSellerMapper.setStatus(status, sellerId);
    }
}
